<template>
    <div>
        <a-card>
            <zh-form  :model="queryParam"  labelAlign="right">
                <zh-input prop="fullName" label="姓名"  v-model="queryParam.fullName"></zh-input>
                <zh-input prop="idcard" label="身份证"  v-model="queryParam.idcard"></zh-input>
                <zh-input prop="cellphone" label="手机号"  v-model="queryParam.cellphone"></zh-input>
                <zh-input prop="authStatus" allowClear type="select" :options="dictData.AUTHSTATUS" label="审核状态" v-model="queryParam.authStatus"></zh-input>
                <a-col :span="24" >
                        <span class="table-page-search-submitButtons" style="margin-top:10px"
                              :style="{ height: '40px',float: 'right', overflow: 'hidden' } ">
                              <!--  <a-button type="primary" @click="() =>{this.addBtn()}">新增</a-button>-->
                             <a-button style="margin-left: 8px" type="primary" @click="() =>{this.queryBtn()}">查询</a-button>
                             <a-button style="margin-left: 8px"  @click="() => {this.clearBtn()}">重置</a-button>
                             <a-button type="primary" style="margin-left: 8px" @click="() =>{this.auditBatch('1')}">审核通过</a-button>
                             <a-button type="primary" style="margin-left: 8px" @click="() =>{this.auditBatch('2')}">审核不通过</a-button>
                             <a-button type="primary" style="margin-left: 8px" @click="() =>{this.auditBatch('0')}">解锁</a-button>
                        </span>

                </a-col>
            </zh-form>
        </a-card>
        <zh-table ref="myTable" :url="url" :columns="tableColumn">
            <template  #operate="{ row }">
                <div class="alert-message">
                    <i class="fa fa-exclamation-circle alert-message-icon"></i>
                    <span class="alert-message-content">
                         <span v-if="row.authStatus=='0'">
                             <a-tooltip placement="top">
                                      <template slot="title">
                                      <span>审核通过</span>
                                      </template>
                                      <a-icon style="padding-right:10px;color: #800080;cursor: pointer;" type="check"
                                              @click="auditUser(row,1)" ></a-icon>
                             </a-tooltip>
                              <a-tooltip placement="top">
                                      <template slot="title">
                                      <span>审核不通过</span>
                                      </template>
                                      <a-icon style="padding-right:10px;color: #800080;cursor: pointer;" type="close"
                                              @click="auditUser(row,2)" ></a-icon>
                             </a-tooltip>
                         </span>
                         <span v-if="row.authStatus=='1'">
                              <a-tooltip placement="top">
                                      <template slot="title">
                                      <span>用户已被锁定</span>
                                      </template>
                                      <a-icon style="padding-right:10px;color: #800080;cursor: pointer;" type="lock"></a-icon>
                             </a-tooltip>
                         </span>
                         <span v-if="row.authStatus=='2'">
                             <a-tooltip placement="top">
                                      <template slot="title">
                                      <span>解锁审核不通过</span>
                                      </template>
                                      <a-icon style="padding-right:10px;color: #800080;cursor: pointer;" type="unlock"
                                              @click="auditUser(row,0)"></a-icon>
                             </a-tooltip>
                         </span>
                     </span>
                </div>
            </template>
        </zh-table>
    </div>
</template>

<script>
    import { getBatchDict,getBusiUserList,updateBusiAuthStatus} from "@/services/system/api"
    export default {
        name: "UserAudit",
        data(){
            return{
                advanced:false,
                queryParam:{},//查询条件
                dictData:[],//数据字典
                tablePage: {
                    total: 0,
                    currentPage: 1,
                    pageNum: 1,
                    pageSize: 20
                },
                tableColumn:[
                    {type: "checkbox",width: 40,fixed: "left",align: "center"},
                    { type: 'seq', width: 80, fixed: 'left', align: 'center', title: '序号' },
                    { field: 'fullName', title: '姓名',   align: 'center', width: 150 },
                    { field: 'idcard', title: '身份证',  align: 'center', width: 150 },
                    { field: 'email', title: '邮箱',  align: 'center', width: 150 },
                    { field: 'cellphone', title: '手机号',   align: 'center', width: 150 },
                    { field: 'userType', title: '用户类型', align: 'center', editRender:{name: 'ASelect',options:[],optionProps:{value:'dictKey',label:'dictValue'}}, width: 150 },
                    { field: 'authStatus', title: '审核状态', align: 'center', editRender:{name: 'ASelect',options:[],optionProps:{value:'dictKey',label:'dictValue'}}, width: 150 },
                    { field: 'cellphone', title: '手机号',   align: 'center', width: 150 },
                    { field: 'orgName', title: '企业名称',   align: 'center', width: 150 },
                    { field: 'creditCode', title: '统一社会信用代码',   align: 'center', width: 150 },
                    { field: 'operate', title: '操作', fixed: 'right',align: 'center', width: 150,slots: {
                            // 使用插槽模板渲染
                            default: 'operate'}},


                ],
                tableData:[],
                url:getBusiUserList,
                auditForm:{

                },
                auditVisible:false,
            }
        },
        created(){
            this.initDict();
        },
        methods:{
            //初始化字典
            initDict(){
                const params = {}
                params.dictFields = 'AUTHSTATUS,USERTYPE'
                this.$http.post(getBatchDict,params).then(res => {
                    this.dictData = res.result;
                    this.tableColumn[6].editRender.options = this.dictData.USERTYPE;
                    this.tableColumn[7].editRender.options = this.dictData.AUTHSTATUS;
                });
            },
            queryBtn(){
                const params = {}
                this.$refs.myTable.query(params);
            },
            auditUser(row,type){
                const params = {}
                let idList=[];
                idList.push(row.id);
                params.idList =idList;
                params.authStatus=type;
                this.$http.post(updateBusiAuthStatus,params).then(res => {
                    console.log(res);
                    const params = {}
                    this.$refs.myTable.query(params);
                });
            },
            auditBatch(type){
                let selectRecords = this.$refs.myTable.getCheckboxRecords();
                if(selectRecords.length>0){
                    let authStatus=selectRecords[0].authStatus;
                    let idList=[];

                    for(let i=0;i<selectRecords.length;i++){
                        if(selectRecords[i].authStatus!=authStatus){
                            this.$notification.warn({
                                message: '批量审核',
                                description: `请选择当前审核状态一致的人员进行审核`
                            })
                            return
                        }
                        idList.push(selectRecords[i].id);
                    }
                    if(type=='0'){
                        if(authStatus=='1'){
                            this.$notification.error({
                                message: '批量审核',
                                description: `已审核通过的用户无法解锁`
                            })
                            return
                        }
                        if(authStatus=='0'){
                            this.$notification.warn({
                                message: '批量审核',
                                description: `勾选的用户不是锁定状态不需要解锁`
                            })
                            return
                        }
                    }
                    if(type!='0'&&authStatus!='0'){
                        this.$notification.error({
                            message: '批量审核',
                            description: `勾选的用户不是未审核状态`
                        })
                        return
                    }

                    const params = {}
                    params.idList =idList;
                    params.authStatus=type;
                    this.$http.post(updateBusiAuthStatus,params).then(res => {
                        console.log(res);
                        const params = {}
                        this.$refs.myTable.query(params);
                    });
                }else{
                    this.$notification.warn({
                        message: '批量审核',
                        description: `请先勾选需要审核的人员`
                    })
                }
            }

        }
    }

</script>